package com.shiku.im.security.dao.Impl;

import com.shiku.common.model.PageResult;
import com.shiku.im.repository.MongoRepository;
import com.shiku.im.security.dao.LineConfigDao;
import com.shiku.im.security.entity.LineConfig;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

/**
 * @Description: TODO
 * @Author xie yuan yang
 * @Date 2020/3/6
 **/
@Repository
public class LineConfigDaoImpl extends MongoRepository<LineConfig, ObjectId> implements LineConfigDao {
    @Override
    public Class<LineConfig> getEntityClass() {
        return LineConfig.class;
    }

    @Override
    public LineConfig sava(LineConfig lineConfig) {
        return getDatastore().save(lineConfig);
    }

    @Override
    public PageResult<LineConfig> queryLineConfigList(int pageIndex, Integer pageSize) {
        PageResult<LineConfig> result = new PageResult<>();
        Query query = createQuery();
        query.with(createPageRequest(pageIndex-1,pageSize));
        result.setData(queryListsByQuery(query));
        result.setCount(count(query));
        return result;
    }

    @Override
    public void deleteLineConfig(ObjectId objectId) {
        deleteByQuery(createQuery(objectId));
    }


}
